package org.jspresso.framework.application.frontend.action.entity.creation;

import java.util.Map;

import org.jspresso.framework.application.frontend.action.std.EditComponentAction;
import org.jspresso.framework.model.component.IComponent;
import org.jspresso.framework.model.descriptor.IComponentDescriptor;
import org.jspresso.framework.model.entity.IEntity;

public class ChoosenEntityCreationAction<E, F, G> extends EditComponentAction<E, F, G> {

	@Override
	protected Object getComponentToEdit(Map<String, Object> context) {
		IComponentDescriptor<IEntity> selectedDescriptor = getActionParameter(context);
		if(IEntity.class.isAssignableFrom(selectedDescriptor.getComponentContract()))
		{
			IEntity entity = getBackendController(context).getEntityFactory().createEntityInstance(selectedDescriptor.getComponentContract());
			return entity;
		}
		else {
			IComponent component = getBackendController(context).getEntityFactory().createComponentInstance(selectedDescriptor.getComponentContract());
			return component;
		}
	}

}
